package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.ejia.pojo.user;
import com.ejia.server.UserService;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;
import java.awt.Font;
import javax.swing.SwingConstants;

public class YQFKadd extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private static ArrayList<user> users;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					YQFKadd frame = new YQFKadd();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public YQFKadd() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(YQFKadd.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setTitle("添加疫情防控记录");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 512);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("疫情防控添加");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setFont(new Font("宋体", Font.PLAIN, 32));
		label.setBounds(110, 36, 207, 50);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("姓名");
		label_1.setFont(new Font("宋体", Font.PLAIN, 28));
		label_1.setBounds(44, 101, 125, 38);
		contentPane.add(label_1);
		
		JLabel lblNewLabel = new JLabel("防疫状态");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 28));
		lblNewLabel.setBounds(44, 179, 125, 38);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("行程码");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 28));
		lblNewLabel_1.setBounds(44, 253, 125, 38);
		contentPane.add(lblNewLabel_1);
		
		JLabel label_2 = new JLabel("登记时间");
		label_2.setFont(new Font("宋体", Font.PLAIN, 28));
		label_2.setBounds(44, 320, 125, 38);
		contentPane.add(label_2);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 24));
		textField.setBounds(213, 261, 170, 27);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_1.setColumns(10);
		textField_1.setBounds(213, 328, 170, 27);
		contentPane.add(textField_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setFont(new Font("宋体", Font.PLAIN, 24));
		users=UserService.findYZXXGL();
		Object[][] data1= new Object[users.size()][];
		for (int i = 0; i < data1.length; i++) {
			data1[i]=new Object[] {
					users.get(i).getRealname()
			};
		}
		String[] data = new String[users.size()];
		for (int i = 0; i < data1.length; i++) {
			data[i]=(String) data1[i][0];
		}
		comboBox.setModel(new DefaultComboBoxModel(data));
		comboBox.setBounds(213, 109, 170, 27);
		contentPane.add(comboBox);
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setFont(new Font("宋体", Font.PLAIN, 24));
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"绿码", "黄码", "红码"}));
		comboBox_1.setBounds(213, 187, 170, 27);
		contentPane.add(comboBox_1);
		
		JButton button = new JButton("添加");
		button.setFont(new Font("宋体", Font.PLAIN, 32));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String name=(String) comboBox.getSelectedItem();
				int status=comboBox_1.getSelectedIndex()+1;
				String city=textField.getText();
				String time=textField_1.getText();
				users=UserService.find1(name);
				if (UserService.add(users.get(0).getId(), users.get(0).getHid().getParentid(), status, city, time)) {
					JOptionPane.showMessageDialog(null, "添加成功");
					new YQFK().setVisible(true);
					dispose();
				}else {
					JOptionPane.showMessageDialog(null, "添加失败");
				}
			}
		});
		button.setBounds(60, 391, 123, 50);
		contentPane.add(button);
		
		JButton button_1 = new JButton("取消");
		button_1.setFont(new Font("宋体", Font.PLAIN, 32));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new YQFK().setVisible(true);
				dispose();
			}
		});
		button_1.setBounds(243, 391, 123, 50);
		contentPane.add(button_1);
		setLocationRelativeTo(null);
	}
}
